package com.tfjybj.msg.dingmessage.utils;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.taobao.api.ApiException;

/**
 * @Description:
 * @Author: xuziguo
 * @Date: 2021/4/17 下午 2:28
 * @Modified By:
 * @Modify Date:
 */
public class DingUtil {

    private DingUtil() {
    }

    //获取企业的token
    //（参考钉钉文档：https://developers.dingtalk.com/document/app/obtain-orgapp-token）
    public static String accessToken() {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
        OapiGettokenRequest request = new OapiGettokenRequest();
        request.setAppkey("dingt452prfmxlwv9dsx");
        request.setAppsecret("HojvOyIB0eVdmLurfK4d8RNkxO_2JviKyT4MsKkpWVt81NkKRiP0Q0X_gXQlCKR-");
        request.setHttpMethod("GET");
        try {
            OapiGettokenResponse res = client.execute(request);
            return res.getAccessToken();
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return null;
    }
}
